package lxs.swift.fn;

import lxs.swift.operation.Try;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;


public interface Consume<T, E extends Throwable> extends Fn<Consumer<T>> {
    void accept(T t) throws E;

    @Override
    default Consumer<T> std() {
        return (t) -> Try.runOf(() -> accept(t));
    }

    static <E extends Throwable> Consume<E, E> explode() {
        return (t) -> {
            throw t;
        };
    }

    static <E extends Throwable> Consume<E, E> panic(@NotNull E error) {
        return (t) -> {
            throw error;
        };
    }

}
